package com.wc._16届国特冲刺营._09_数据结构_线段树屠龙术.最大公约数;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/5/30 16:48
 * @description
 * https://www.lanqiao.cn/courses/51805/learning/?id=4072920&compatibility=false
 */
public class Main {
    /**
     * 思路：
     * 有 1 的时候 n - x
     * 没有 1 的时候 是否可以造 1
     * 不能造说明无法满足
     * 可以造, 看造 1 的最短路是多少, 可以用到二分
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010 << 2;
    static int[] g = new int[N], sum = new int[N], a = new int[N];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        build(1, 1, n);
        if (g[1] != 1) out.println(-1);
        else {
            if (sum[1] > 0) out.println(n - sum[1]);
            else {
                int l = 1, r = n;
                while (l < r) {
                    int mid = l + r >> 1;
                    if (check(mid)) r = mid;
                    else l = mid + 1;
                }
                out.println(n - 1 + l - 1);
            }
        }
        out.flush();
    }

    static void build(int u, int l, int r)  {
        if (l == r) {
            g[u] = a[l];
            sum[u] = a[l] == 1 ? 1 : 0;
            return;
        }

        int mid = l + r >> 1;
        build(u << 1, l, mid);
        build(u << 1 | 1, mid + 1, r);
        pushUp(u);
    }

    static void pushUp(int u) {
        g[u] = gcd(g[u << 1], g[u << 1 | 1]);
        sum[u] = sum[u << 1] + sum[u << 1 | 1];
    }

    static int gcd(int a, int b) {
        return b > 0 ? gcd(b, a % b) : a;
    }

    static boolean check(int len) {
        for (int l = 1; l <= n - len + 1; l++) {
            int r = l + len - 1;
            if (query(1, 1, n, l, r) == 1) return true;
        }
        return false;
    }

    static int query(int u, int l, int r, int ql, int qr) {
        if (l == ql && r == qr) {
            return g[u];
        }
        int mid = l + r >> 1;
        if (qr <= mid) return query(u << 1, l, mid, ql, qr);
        else if (ql > mid) return query(u << 1 | 1, mid + 1, r, ql, qr);
        int L = query(u << 1, l, mid, ql, mid);
        int R = query(u << 1 | 1, mid + 1, r, mid + 1, qr);
        return gcd(L, R);
    }
}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

